package com.fjzx.androidframe.ui.textinput;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * 必填项TextView
 *
 * @author xiongyongcong
 */
public class RequiredTextView extends TextView {
    public RequiredTextView(Context context) {
        this(context, null);
    }

    public RequiredTextView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public RequiredTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void setText(CharSequence text, BufferType type) {
        String requiredText = "* " + text;
        SpannableString spannableString = new SpannableString(requiredText);
        spannableString.setSpan(new ForegroundColorSpan(Color.RED), 0,1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        super.setText(spannableString, type);
    }
}
